<?php


class SimplebatchSubmissionUpdateWidget extends CWidget {

    public $submission;

    public function run(){
        if (isset($_POST['Submission'])){
            $this->submission->setScenario('update');
            $this->submission->setAttributes($_POST['Submission']);
            $this->submission->save();
        }
        
        if ($_GET['action'] == 'download') {
			$this->downloadSource();
		}
        
        $this->render('submissionupdate', array(
            'submission' => $this->submission,
        ));
    }
    
    
    private function downloadSource() {
		ob_clean();
		
		$contest = Contest::model()->findByPk($this->submission->contest_id);
		$submitter = User::model()->findByPk($this->submission->submitter_id);
		
		header('Content-type: text/plain');
		header('Content-Disposition: attachment; filename="submission-'.$contest->name.'-'.$submitter->username.'-'.$this->submission->id.'.'.$this->submission->getSubmitContent('source_lang').'"');
		echo $this->submission->getSubmitContent('source_content'); 
		exit;
	}
    
}
